package com.bjb.vr.common.service;

import cn.hutool.crypto.digest.MD5;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bjb.vr.common.ao.ResClientCloudAo;
import com.bjb.vr.common.ao.ResContentAo;
import com.bjb.vr.common.constant.AliOssConstants;
import com.bjb.vr.common.constant.CacheConstant;
import com.bjb.vr.common.constant.ThreadLocalConstant;
import com.bjb.vr.common.dto.ResContent;
import com.bjb.vr.common.dto.ResContentAuthority;
import com.bjb.vr.common.dto.ResFavorites;
import com.bjb.vr.common.dto.ResPlatformResource;
import com.bjb.vr.common.mapper.ResContentAuthorityMapper;
import com.bjb.vr.common.mapper.ResContentMapper;
import com.bjb.vr.common.result.BaseResult;
import com.bjb.vr.common.result.CommonResult;
import com.bjb.vr.common.utils.AliyunOssUtil;
import com.bjb.vr.common.utils.DateTimeUtil;
import com.bjb.vr.common.utils.GuavaCacheUtil;
import com.bjb.vr.common.utils.ThreadLocalUtil;
import com.bjb.vr.common.vo.*;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.google.common.base.Splitter;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ExecutionException;

/**
 * @author admin
 * @description 针对表【res_content(资源表)】的数据库操作Service实现
 * @createDate 2022-03-18 18:00:07
 */
@Service
public class ResContentService extends ServiceImpl<ResContentMapper, ResContent> {

    private static AliyunOssUtil ossUtil = null;

    static {
        ossUtil = new AliyunOssUtil.Builder().build(AliOssConstants.ENDPOINT, AliOssConstants.ACCESS_KEY_ID, AliOssConstants.ACCESS_KEY_SECRET);
    }

    @Resource
    ResContentMapper resContentMapper;

    @Resource
    ResDictionaryService dictionaryService;

    @Resource
    ResPlatformResourceService platformResourceService;

    @Resource
    FileOperationService fileOperationService;

    @Resource
    ResContentAuthorityMapper contentAuthorityMapper;


    public boolean updateResContentUseCount(Long contentId) {
        Assert.notNull(contentId, "资源id不能为空");
        UpdateWrapper wrapper = new UpdateWrapper();
        wrapper.eq("id", contentId);
        wrapper.setSql("use_count = use_count + 1");
        this.update(wrapper);
        return true;
    }

    /**
     * 根据条件查询某个课程的具体内容
     *
     * @param resContentAo
     * @return
     */
    public ResPlatformVo queryContentInfo(ResContentAo resContentAo) throws Exception {
        //查询内容
        ResPlatformResource resource = platformResourceService.getByResId(resContentAo.getId());
        if (resource == null) {
            return new ResPlatformVo();
        }
        // 封装参数
        ResPlatformVo platformVo = new ResPlatformVo();
        BeanUtils.copyProperties(resource, platformVo);
        // 设置章节列表
        if (StringUtils.isNotBlank(resource.getSections())) {
            List<String> splitToList = Splitter.on("#").splitToList(resource.getSections());
            JSONArray jsonArray = new JSONArray();
            for (int i = 0; i < splitToList.size(); i++) {
                JSONObject jsonObject = new JSONObject();
                String split = splitToList.get(i);
                jsonObject.put("order", i + 1);
                String name = split.split("\\^")[0];
                jsonObject.put("name", name);
                String startAndtime = split.split("\\^")[1];
                if (startAndtime.length() == 1) {
                    jsonObject.put("start", "");
                    jsonObject.put("time", "");
                } else {
                    String start = startAndtime.split("\\&")[0];
                    String time = startAndtime.split("\\&")[1];
                    jsonObject.put("start", start);
                    jsonObject.put("time", time);
                }
                jsonArray.add(jsonObject);
            }
            platformVo.setSections(jsonArray.toJSONString());
        }
        // 查询是否被收藏
        UmsAccountVo umsAccountVo = (UmsAccountVo) ThreadLocalUtil.get(ThreadLocalConstant.USER_ACCOUNT_INFO);
        try {
            List<ResFavorites> resFavorites = GuavaCacheUtil.getFavoritesCache().get(umsAccountVo.getUserId() + CacheConstant.SEPARATOR + platformVo.getResId());
            if (CollectionUtils.isEmpty(resFavorites)) {
                platformVo.setIsFavorites(false);
            } else {
                platformVo.setIsFavorites(true);
            }
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }
        // 设置字典值
        if (StringUtils.isNotBlank(resource.getPreImagePath())) {
            platformVo.setPreImagePath(fileOperationService.downloadFile(resource.getPreImagePath()));
        }
        if (StringUtils.isNotBlank(resource.getCasePath())) {
            platformVo.setCasePath(fileOperationService.downloadFile(resource.getCasePath()));
        }
        if (StringUtils.isNotBlank(resource.getShowContentPath())) {
            platformVo.setShowContentPath(fileOperationService.downloadFile(resource.getShowContentPath()));
        }
        return platformVo;
    }


    /**
     * 根据条件查询平台某个课程的具体内容
     *
     * @param resContentAo
     * @return
     */
    public ResPlatformVo queryCusResBundleResPlat(ResContentAo resContentAo) throws Exception {
        //查询内容
        ThreadLocalUtil.set(ThreadLocalConstant.NO_TENANT_ID_VERIFY, true);
        ResPlatformResource resource = platformResourceService.queryCusResBundleResPlat(resContentAo);
        ThreadLocalUtil.set(ThreadLocalConstant.NO_TENANT_ID_VERIFY, false);
        if (resource == null) {
            return new ResPlatformVo();
        }
        // 封装参数
        ResPlatformVo platformVo = new ResPlatformVo();
        BeanUtils.copyProperties(resource, platformVo);
        // 设置章节列表
        if (StringUtils.isNotBlank(resource.getSections())) {
            List<String> splitToList = Splitter.on("#").splitToList(resource.getSections());
            JSONArray jsonArray = new JSONArray();
            for (int i = 0; i < splitToList.size(); i++) {
                JSONObject jsonObject = new JSONObject();
                String split = splitToList.get(i);
                jsonObject.put("order", i + 1);
                String name = split.split("\\^")[0];
                String startAndtime = split.split("\\^")[1];
                String start = startAndtime.split("\\&")[0];
                String time = startAndtime.split("\\&")[1];
                jsonObject.put("name", name);
                jsonObject.put("start", start);
                jsonObject.put("time", time);
                jsonArray.add(jsonObject);
            }
            platformVo.setSections(jsonArray.toJSONString());
        }
        return platformVo;
    }

    public BaseResult<List<ResClientCourseVo>> getClientResCourseList(String udid) {
        ThreadLocalUtil.set(ThreadLocalConstant.NO_TENANT_ID_VERIFY, true);
        BaseResult<List<ResClientCourseVo>> result = new CommonResult<List<ResClientCourseVo>>(false);
        List<ResClientCourseVo> resContentList = resContentMapper.getClientResCourseList(udid);
        ThreadLocalUtil.set(ThreadLocalConstant.NO_TENANT_ID_VERIFY, false);
        buildNeedInfo(resContentList);

        result = CommonResult.Ok().setResult(resContentList);
        return result;
    }

    /**
     * 构建需要的信息
     *
     * @param resClientCourseVoList
     * @return
     */
    private void buildNeedInfo(List<ResClientCourseVo> resClientCourseVoList) {
        resClientCourseVoList.forEach(resClientCourseVo -> {
            try {
                if (StringUtils.isNotBlank(resClientCourseVo.getPreImagePath())) {
                    resClientCourseVo.setPreImagePath(fileOperationService.downloadFile(resClientCourseVo.getPreImagePath()));
                }
                if (StringUtils.isNotBlank(resClientCourseVo.getContentPath())) {
                    resClientCourseVo.setContentPath(fileOperationService.downloadFile(resClientCourseVo.getContentPath()));
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        });
    }

    /**
     * （运营端）课程资源列表查询
     *
     * @param resContentAo
     * @return
     */
    public IPage<OptContentVo> queryResourcesList(ResContentAo resContentAo) {
        ThreadLocalUtil.set(ThreadLocalConstant.NO_TENANT_ID_VERIFY, true);
        // 分页条件
        MPJLambdaWrapper<OptContentVo> lambdaQueryWrapper = new MPJLambdaWrapper();
        lambdaQueryWrapper
                .select(ResContent::getId)
                .select(ResContent::getVersion)
                .select(ResContent::getPreImagePath)
                .select(ResContent::getName)
                .selectAs(ResContent::getDicThemeCode, "themeCode")
                .selectAs(ResContent::getDicPeriodCode, "period")
                .selectAs(ResContent::getDicLevelCode, "level")
                .selectAs(ResContent::getDicSubjectCode, "subject")
                .selectAs(ResContent::getDicTypeCode, "resType")
                .selectAs(ResContent::getContentSize, "capacity");
        lambdaQueryWrapper.eq(StringUtils.isNotBlank(resContentAo.getTheme()), ResContent::getDicThemeCode, resContentAo.getTheme());
        lambdaQueryWrapper.like(StringUtils.isNotBlank(resContentAo.getName()), ResContent::getName, resContentAo.getName());
        lambdaQueryWrapper.eq(StringUtils.isNotBlank(resContentAo.getPeriod()), ResContent::getDicPeriodCode, resContentAo.getPeriod());
        lambdaQueryWrapper.eq(StringUtils.isNotBlank(resContentAo.getLevel()), ResContent::getDicLevelCode, resContentAo.getLevel());
        lambdaQueryWrapper.eq(StringUtils.isNotBlank(resContentAo.getSubject()), ResContent::getDicSubjectCode, resContentAo.getSubject());
        lambdaQueryWrapper.eq(StringUtils.isNotBlank(resContentAo.getResType()), ResContent::getDicTypeCode, resContentAo.getResType());
        lambdaQueryWrapper.orderByDesc(ResContent::getId);
        // 分页查询
        IPage<OptContentVo> voIPage = resContentMapper.selectJoinPage(new Page<>(resContentAo.getCurrent(), resContentAo.getSize()), OptContentVo.class, lambdaQueryWrapper);
        buildContentInfo(voIPage.getRecords(), resContentAo.getTenantId());
        return voIPage;
    }

    /**
     * （运营端）眼镜云端资源列表查询
     *
     * @param resClientCloudAo
     * @return
     */
    public List<ResClientCloudVo> queryGlassResourcesList(ResClientCloudAo resClientCloudAo) {
        List<ResClientCloudVo> resClientCloudVoList = resContentMapper.queryGlassResourcesList(resClientCloudAo.getUdid());
        buildRealPathInfo(resClientCloudVoList);
        return resClientCloudVoList;
    }


    private void buildRealPathInfo(List<ResClientCloudVo> resClientCloudVoList) {
        resClientCloudVoList.forEach(resClientCourseVo -> {
            try {
                if (StringUtils.isNotBlank(resClientCourseVo.getPreImagePath())) {
                    resClientCourseVo.setPreImagePath(fileOperationService.downloadFile(resClientCourseVo.getPreImagePath()));
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        });
    }

    /**
     * 封装字典值
     *
     * @param records
     * @param tenantId
     * @return
     */
    private void buildContentInfo(List<OptContentVo> records, String tenantId) {
        records.stream().forEach(r -> {
            LocalDate nowDate = DateTimeUtil.getLocalDate(new Date());
            r.setResName(r.getName());
            if (StringUtils.isNotBlank(r.getPeriod())) {
                r.setPeriod(dictionaryService.getResDictionaryByCode(r.getPeriod()).getDictName());
            }
            if (StringUtils.isNotBlank(r.getLevel())) {
                r.setLevel(dictionaryService.getResDictionaryByCode(r.getLevel()).getDictName());
            }
            if (StringUtils.isNotBlank(r.getSubject())) {
                r.setSubject(dictionaryService.getResDictionaryByCode(r.getSubject()).getDictName());
            }
            if (StringUtils.isNotBlank(r.getResType())) {
                r.setResType(dictionaryService.getResDictionaryByCode(r.getResType()).getDictName());
            }
            if (StringUtils.isNotBlank(r.getPreImagePath())) {
                r.setPreImagePath(ossUtil.getFileUrl(r.getPreImagePath()));
            }
            // 设置资源是否已购买
            if (StringUtils.isNotBlank(tenantId)) {
                LambdaQueryWrapper<ResContentAuthority> queryWrapper = new LambdaQueryWrapper<>();
                queryWrapper.eq(ResContentAuthority::getTenantId, tenantId);
                queryWrapper.eq(ResContentAuthority::getContentId, r.getId());
                List<ResContentAuthority> authorityList = contentAuthorityMapper.selectList(queryWrapper);
                authorityList.stream().forEach(authRes -> {
                    LocalDate validStartDate = authRes.getContValidStartDate();
                    LocalDate validEndDate = authRes.getContValidEndDate();
                    if (validStartDate == null) {
                        return;
                    }
                    if (validEndDate != null && nowDate.compareTo(validStartDate) >= 0 && nowDate.compareTo(validEndDate) <= 0) {
                        r.setPurchase(1);
                    }
                    if (validEndDate == null && nowDate.compareTo(validStartDate) >= 0){
                        r.setPurchase(1);
                    }
                });

            }
        });
    }

    /**
     * （运营端）新增课程资源
     *
     * @param resContentAo
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public boolean addResource(ResContentAo resContentAo) {
        ResContent resContent = new ResContent();
        BeanUtils.copyProperties(resContentAo, resContent);
        resContent.setDicThemeCode(resContentAo.getTheme());
        resContent.setDicTypeCode(resContentAo.getResType());
        resContent.setDicPeriodCode(resContentAo.getPeriod());
        resContent.setDicLevelCode(resContentAo.getLevel());
        resContent.setDicSubjectCode(resContentAo.getSubject());
        resContent.setDicTermCode(resContentAo.getTerm());
        resContent.setDicSourceCode(resContentAo.getSource());
        resContent.setDicTypeLanguage(resContentAo.getLanguage());
        resContent.setDicTypePress(resContentAo.getPress());
        // 设置资源类型type字段的值
        if (StringUtils.isNotBlank(resContent.getDicTypeCode())) {
            if (resContent.getDicTypeCode().equals("1020")) {
                resContent.setType("cus_vr");
            }
            if (resContent.getDicTypeCode().equals("1021")) {
                resContent.setType("video");
            }
            if (resContent.getDicTypeCode().equals("1022")) {
                resContent.setType("image");
            }
        }
        // [{"order":1,"name":"test1","time":"60","start":"0"},{"order":2,"name":"test2","start":"1","time":"60"}]
        // 雨点^0&38#咏鹅^38&21#悯农^59&17
        if (StringUtils.isNotBlank(resContentAo.getSections())) {
            JSONArray jsonArray = (JSONArray) JSONArray.parse(resContentAo.getSections());
            StringBuilder sectionsBuilder = new StringBuilder();
            for (Object object : jsonArray) {
                JSONObject jsonObject = (JSONObject) object;
                sectionsBuilder.append(jsonObject.get("name"))
                        .append("^")
                        .append(jsonObject.get("start"))
                        .append("&")
                        .append(jsonObject.get("time"))
                        .append("#");
            }
            sectionsBuilder.deleteCharAt(sectionsBuilder.lastIndexOf("#"));
            resContent.setSections(sectionsBuilder.toString());
        }
        try {
            resContentMapper.insert(resContent);
            return true;
        } catch (Exception e) {
            log.error(e.getMessage());
            return false;
        }
    }

    /**
     * （运营端）课程资源字典列表查询
     *
     * @param resContentAo
     * @return
     */
    public List<ResDictionaryVo> queryDictList(ResContentAo resContentAo) {
        // 根据类型查询
        List<ResDictionaryVo> dictionaryVos = new ArrayList<>();
        String[] split = resContentAo.getDictType().split("&");
        for (String ss : split) {
            List<ResDictionaryVo> voList = dictionaryService.getResDictionaryList(ss);
            dictionaryVos.addAll(voList);
        }
        return dictionaryVos;
    }

    /**
     * （运营端）课程资源文件上传
     *
     * @param file
     * @return
     */
    public JSONObject uploadResourceFile(MultipartFile file) throws IOException {
        String url = fileOperationService.uploadFile(file);
        String md5Value = MD5.create().digestHex(file.getBytes());
        JSONObject object = new JSONObject();
        object.put("uploadUrl", url);
        object.put("contentSize", file.getSize());
        object.put("contentCheck", md5Value);
        return object;
    }

    /**
     * （运营端）课程资源详情
     *
     * @param resContentAo
     * @return
     */
    public OptContentVo queryResourcesOne(ResContentAo resContentAo) {
        ThreadLocalUtil.set(ThreadLocalConstant.NO_TENANT_ID_VERIFY, true);
        ResContent resContent = resContentMapper.selectById(resContentAo.getId());
        if (Objects.isNull(resContent)) {
            return new OptContentVo();
        }
        OptContentVo optContentVo = new OptContentVo();
        BeanUtils.copyProperties(resContent, optContentVo);
        // 封装字典数据
        buildDictValue(resContent, optContentVo);
        // 设置章节
        if (StringUtils.isNotBlank(resContent.getSections())) {
            buildSection(resContent, optContentVo);
        }
        optContentVo.setCapacity(resContent.getContentSize());
        return optContentVo;
    }

    /**
     * 封装章节信息
     *
     * @param resContent
     * @param optContentVo
     */
    private void buildSection(ResContent resContent, OptContentVo optContentVo) {
        List<String> splitToList = Splitter.on("#").splitToList(resContent.getSections());
        JSONArray jsonArray = new JSONArray();
        for (int i = 0; i < splitToList.size(); i++) {
            JSONObject jsonObject = new JSONObject();
            String split = splitToList.get(i);
            jsonObject.put("order", i + 1);
            String name = split.split("\\^")[0];
            jsonObject.put("name", name);
            String startAndtime = split.split("\\^")[1];
            if (startAndtime.length() == 1) {
                jsonObject.put("start", "");
                jsonObject.put("time", "");
            } else {
                String start = startAndtime.split("\\&")[0];
                String time = startAndtime.split("\\&")[1];
                jsonObject.put("start", start);
                jsonObject.put("time", time);
            }
            jsonArray.add(jsonObject);
        }
        optContentVo.setSections(jsonArray.toJSONString());
    }

    /**
     * 封装字典数据
     *
     * @param resContent
     * @param optContentVo
     */
    private void buildDictValue(ResContent resContent, OptContentVo optContentVo) {
        // 封装字典值
        if (StringUtils.isNotBlank(resContent.getPreImagePath())) {
            optContentVo.setPreImagePath(fileOperationService.downloadFile(resContent.getPreImagePath()));
        }
        if (StringUtils.isNotBlank(resContent.getCasePath())) {
            optContentVo.setCasePath(fileOperationService.downloadFile(resContent.getCasePath()));
        }
        if (StringUtils.isNotBlank(resContent.getShowContentPath())) {
            optContentVo.setShowContentPath(fileOperationService.downloadFile(resContent.getShowContentPath()));
        }
        if (StringUtils.isNotBlank(resContent.getDicPeriodCode())) {
            optContentVo.setPeriod(dictionaryService.getResDictionaryByCode(resContent.getDicPeriodCode()).getDictName());
        }
        if (StringUtils.isNotBlank(resContent.getDicLevelCode())) {
            optContentVo.setLevel(dictionaryService.getResDictionaryByCode(resContent.getDicLevelCode()).getDictName());
        }
        if (StringUtils.isNotBlank(resContent.getDicSubjectCode())) {
            optContentVo.setSubject(dictionaryService.getResDictionaryByCode(resContent.getDicSubjectCode()).getDictName());
        }
        if (StringUtils.isNotBlank(resContent.getDicTypeCode())) {
            optContentVo.setResType(dictionaryService.getResDictionaryByCode(resContent.getDicTypeCode()).getDictName());
        }
        if (StringUtils.isNotBlank(resContent.getDicTypePress())) {
            optContentVo.setPress(dictionaryService.getResDictionaryByCode(resContent.getDicTypePress()).getDictName());
        }
        if (StringUtils.isNotBlank(resContent.getDicTypeLanguage())) {
            optContentVo.setLanguage(dictionaryService.getResDictionaryByCode(resContent.getDicTypeLanguage()).getDictName());
        }
        if (StringUtils.isNotBlank(resContent.getDicSourceCode())) {
            optContentVo.setSource(dictionaryService.getResDictionaryByCode(resContent.getDicSourceCode()).getDictName());
        }
        if (StringUtils.isNotBlank(resContent.getDicThemeCode())) {
            optContentVo.setTheme(dictionaryService.getResDictionaryByCode(resContent.getDicThemeCode()).getDictName());
        }
        if (StringUtils.isNotBlank(resContent.getDicTermCode())) {
            optContentVo.setTerm(dictionaryService.getResDictionaryByCode(resContent.getDicTermCode()).getDictName());
        }
        if (StringUtils.isNotBlank(resContent.getSupportDevices())) {
            String[] split = resContent.getSupportDevices().split(",");
            StringBuilder builder = new StringBuilder();
            for (String ss : split) {
                String dictName = dictionaryService.getResDictionaryByCode(ss).getDictName();
                builder.append(dictName).append(",");
            }
            builder.deleteCharAt(builder.length() - 1);
            optContentVo.setSupportDevicesNames(builder.toString());
        }
    }

    /**
     * （运营端）更新课程资源
     *
     * @param resContentAo
     * @return
     */
    public boolean updateResource(ResContentAo resContentAo) {
        ResContent content = resContentMapper.selectById(resContentAo.getId());
        ResContent resContent = new ResContent();
        BeanUtils.copyProperties(resContentAo, resContent);
        resContent.setDicThemeCode(resContentAo.getTheme());
        resContent.setDicTypeCode(resContentAo.getResType());
        resContent.setDicPeriodCode(resContentAo.getPeriod());
        resContent.setDicLevelCode(resContentAo.getLevel());
        resContent.setDicSubjectCode(resContentAo.getSubject());
        resContent.setDicTermCode(resContentAo.getTerm());
        resContent.setDicSourceCode(resContentAo.getSource());
        resContent.setDicTypeLanguage(resContentAo.getLanguage());
        resContent.setDicTypePress(resContentAo.getPress());
        if (StringUtils.isNotBlank(content.getContentCheck()) && !resContentAo.getContentCheck().equals(content.getContentCheck())) {
            Integer version = Integer.valueOf(content.getVersion()) + 1;
            resContent.setVersion(String.valueOf(version));
        }
        if (StringUtils.isNotBlank(resContentAo.getSections())) {
            JSONArray jsonArray = (JSONArray) JSONArray.parse(resContentAo.getSections());
            StringBuilder sectionsBuilder = new StringBuilder();
            for (Object object : jsonArray) {
                JSONObject jsonObject = (JSONObject) object;
                sectionsBuilder.append(jsonObject.get("name"))
                        .append("^")
                        .append(jsonObject.get("start"))
                        .append("&")
                        .append(jsonObject.get("time"))
                        .append("#");
            }
            sectionsBuilder.deleteCharAt(sectionsBuilder.lastIndexOf("#"));
            resContent.setSections(sectionsBuilder.toString());
        }
        try {
            resContentMapper.updateById(resContent);
            return true;
        } catch (Exception e) {
            log.error(e.getMessage());
            return false;
        }
    }

    /**
     * 获取获取课程内容分页记录
     *
     * @param resContentAo
     * @return
     */
    public IPage<ResContent> queryResContentPage(ResContentAo resContentAo) {
        // 分页条件
        Page<ResContent> resContentPage1 = new Page<>(resContentAo.getCurrent(), resContentAo.getSize());
        LambdaQueryWrapper<ResContent> lambdaQueryWrapper = new LambdaQueryWrapper();
        lambdaQueryWrapper.like(StringUtils.isNotBlank(resContentAo.getName()), ResContent::getName, resContentAo.getName());

        Page<ResContent> resContentPage = this.page(resContentPage1, lambdaQueryWrapper);
        IPage<ResContent> voIPage = new Page<ResContent>(resContentPage.getCurrent(), resContentPage.getSize(), resContentPage.getTotal());
        voIPage.setRecords(resContentPage.getRecords());
        return voIPage;
    }
}




